import router from '@/router'
import store from '@/store'

/**
 * @Author Tangyuhui
 * @Description 处理bms请求
 * @Date 2019-10-31 11:56:23 星期四
 */
function filterBmsBackendData(response) {
  if (response && response.data) {
    if (response.data.success) {
      return Promise.resolve(response.data.data)
    } else {
      if (response.data.errorMsg.indexOf('重新登录') !== -1 || response.data.errorCode === '027004008' || response.data.errorCode === '027004007' || response.data.errorCode === '026001001') {
        store.dispatch('bmsLogout').then(() => {
          router.push({ path: '/login' })
        })
        return Promise.reject(response.data.errorMsg)
      } else {
        return Promise.reject(response.data.errorMsg)
      }
    }
  } else {
    return Promise.reject('请求出错了，请联系后台人员')
  }
}

const serviceUtil = {
  filterBmsBackendData
}
export default serviceUtil
